<script setup lang="ts">
import { onMounted, ref } from 'vue'
import myApi from './update'
// import { shell } from 'electron';
const rate = ref('')
const isFinish = ref(false)
onMounted(async () => {
  myApi.handleCheckPcUpdate().then((res) => {
    console.log(res)
  })
  myApi.onPcDownloaded(() => {
    console.log('下载完成')
    isFinish.value = true
  })
  myApi.onPcUpdateProgress((_, progress) => {
    console.log('下载进度', progress)
    rate.value = `${progress}%`
  })
})
const openBrowser = () => {
  // shell.openPath('https://www.baidu.com')
}

const showTip = () => {
  setTimeout(() => {
    const myNotification = new Notification('data.fromName', {
      body: 'data.msg',
      badge: '3',
      icon: 'https://workyd.com/image/avator.png'
      // silentBoolean: true //系统提示音
    })
    myNotification.onclick = () => {
      // this.noticeClick(data)/
      console.log(31)
    }
  }, 0)
}
</script>

<template>
  <div>
    <button @click="openBrowser">打开浏览器</button>
    <a href="https://www.baidu.com">跳转</a>
    <button @click="showTip">展示提示fasd</button>
    <div>这是1.1.0的版本</div>
    下载进度：{{ rate }}
    <button @click="() => myApi.handlePcToUpdate()">开始更新</button>
    <button v-if="isFinish" @click="() => myApi.toPcInstall()">安装更新</button>
  </div>
</template>
